import 'package:flutter/material.dart';
import 'package:flutter_enjoy_plus/pages/404.dart';
import 'package:flutter_enjoy_plus/pages/house/components/house_list.dart';
import 'package:flutter_enjoy_plus/pages/house/location_list.dart';
import 'package:flutter_enjoy_plus/pages/login/index.dart';
import 'package:flutter_enjoy_plus/pages/notice/index.dart';
import 'package:flutter_enjoy_plus/pages/profile/index.dart';
import 'package:flutter_enjoy_plus/pages/tabs_page.dart';
import 'package:flutter_enjoy_plus/utils/TokenManager.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      '/': (context) => const TabsPage(),
      '/notice_detail': (context) => const NoticeDetail(),
      '/login': (context) => const LoginPage(),
    },
    // 默认启动页面
    initialRoute: '/',
    onGenerateRoute: (settings) {
      final token = tokenManager.getToken();

      if (token.isEmpty) {
        return MaterialPageRoute(builder: (context) => const LoginPage());
      } else {
        if (settings.name == '/profile') {
          return MaterialPageRoute(
              builder: (context) => ProfilePage(
                  userInfo: settings.arguments as Map<String, dynamic>));
        }
        if (settings.name == '/house') {
          return MaterialPageRoute(builder: (context) => const HouseList());
        }
        if (settings.name == '/add_house') {
          return MaterialPageRoute(builder: (context) => const LocationList());
        }
      }
      return  MaterialPageRoute(builder: (context) => const NotFound());
    },
  ));
}
